#include "register.h"
#include "ui_register.h"

Register::Register(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Register)
{
    ui->setupUi(this);
    QPixmap pixmap = QPixmap(":/img/bg4.jpg");
    QPixmap pix = pixmap.scaled(this->size());
    QPalette pal;
    pal.setBrush(QPalette::Background,QBrush(pix));
    this->setPalette(pal);
    db = Database::getInstance().getDatabase();

}

Register::~Register()
{
    delete ui;
}

void Register::on_pushButton_log_clicked()
{
    QString username = ui->lineEdit_username->text();
    QString passwd = ui->lineEdit_passwd->text();
    QSqlQuery query(db);
    QString sql = QString("insert into users(username,password) values('%1','%2')")
            .arg(username).arg(passwd);

    if(!query.exec(sql))
    {
        QMessageBox::warning(this,"注册","注册失败"+query.lastError().text());
    }else
    {
        QMessageBox::information(this,"注册","注册成功，请重新登录");
        this->close();
    }


}
